package com.lagou.rabbitmqdemo.listener;

import com.lagou.rabbitmqdemo.db.OrderDB;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

@Component
public class MessageListener {

    @RabbitListener(queues = "q.go.dlx")
    public void handleDlxMessage(Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag, @Payload String message) {
        System.out.println("订单编号：" + message + "到达设定时间，进行处理。。。");

        if (OrderDB.expire(message)) {
            System.out.println("已将订单编号：" + message + "设置为过期");
        } else {
            System.out.println("订单编号：" + message + "已支付，无需处理");
        }
    }
}
